//
//  LSYReadScroView.m
//  Cartoon
//
//  Created by dllo on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//
#import "BaseHeader.h"
#import "LSYReadScroView.h"
#import "UIImageView+WebCache.h"
#import "AFNetworkHandler.h"
#import "ZYLImageSize.h"
@interface LSYReadScroView ()
@property (nonatomic, retain) UIView *footView;
@property (nonatomic, retain) UIView *supportView;
@property (nonatomic, retain) UIView *collectView;
@property (nonatomic, retain) UILabel *suppot;
@property (nonatomic, retain) UIButton *supportButton;
@property (nonatomic, retain) UIButton *collectButton;
@property (nonatomic, assign) NSInteger supportCount;
@property (nonatomic, assign) NSInteger collectCount;
@property (nonatomic, retain) UIButton *DownButton;
@property (nonatomic, retain) UIView *garyView;
@property (nonatomic, retain) NSNumber *likeCount;
@end

@implementation LSYReadScroView

- (void)dealloc
{
    [_DownButton release];
    [_collectView release];
    [_supportView release];
    [_supportView release];
    [_collectView release];
    [_footView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame dataDic:(NSDictionary *)dic;
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSupport:dic];
//        [self createGaryView];
    }
    return self;
}

+ (instancetype)readScroViewWithFrame:(CGRect)frame rdataDic:(NSDictionary *)dic
{
    id result = [[[self alloc] initWithFrame:frame dataDic:dic] autorelease];
    return result;
}
/**
 *  赞和收藏按钮 上一篇 下一篇
 */
- (void)createSupport:(NSDictionary *)dic
{
    self.supportView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 4 - 25 * SCREEN_WIDTH / 375, 10 * SCREEN_HEIGHT / 667, 50 * SCREEN_HEIGHT / 667, 50 * SCREEN_WIDTH / 375)];
    self.supportView.layer.cornerRadius = 25 * SCREEN_WIDTH / 375;
    self.supportView.layer.borderWidth = 1;
    self.supportView.layer.borderColor = [UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1].CGColor;
    [self addSubview:self.supportView];
    
    self.supportButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.supportButton.frame = CGRectMake(self.supportView.frame.size.width / 2 - 20 / 2 *SCREEN_WIDTH / 375, self.supportView.frame.size.height / 2 - 20 / 2 * SCREEN_WIDTH / 375, 20 *SCREEN_WIDTH / 375, 20 * SCREEN_WIDTH / 375);
    [self.supportButton setImage:[UIImage imageNamed:@"iconfont-zan2"] forState:UIControlStateNormal];
    [self.supportButton setImage:[UIImage imageNamed:@"iconfont-zan1"] forState:UIControlStateSelected];
    [self.supportView addSubview:self.supportButton];
    [self.supportButton addTarget:self action:@selector(supportAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.collectView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + self.supportView.frame.origin.x, self.supportView.frame.origin.y, self.supportView.frame.size.width, self.supportView.frame.size.height)];
    self.collectView.layer.cornerRadius = 25 * SCREEN_WIDTH / 375;
    self.collectView.layer.borderWidth = 1;
    self.collectView.layer.borderColor = [UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1].CGColor;
    [self addSubview:self.collectView];
    
    self.collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.collectButton.frame = CGRectMake(self.collectView.frame.size.width / 2 - 20 / 2 *SCREEN_WIDTH / 375, self.collectView.frame.size.height / 2 - 20 / 2 * SCREEN_WIDTH / 375, 20 *SCREEN_WIDTH / 375, 20 * SCREEN_WIDTH / 375);
    [self.collectButton setImage:[UIImage imageNamed:@"iconfont-shoucang-3"] forState:UIControlStateNormal];
    [self.collectButton setImage:[UIImage imageNamed:@"iconfont-shoucang-1"] forState:UIControlStateSelected];
    [self.collectView addSubview:self.collectButton];
    [self.collectButton addTarget:self action:@selector(collectAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.suppot = [[UILabel alloc] initWithFrame:CGRectMake(self.supportView.frame.origin.x + self.supportView.frame.size.width / 2 - 50 * SCREEN_WIDTH / 375, self.supportView.frame.size.height + self.supportView.frame.origin.y + 10, 100 * SCREEN_WIDTH / 375, 20 * SCREEN_HEIGHT / 667)];
    self.suppot.textAlignment = NSTextAlignmentCenter;
    /**
     *  赋值
     */
    self.suppot.text = [[dic objectForKey:@"likes_count"] stringValue];
    self.suppot.textColor = [UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1];
    self.suppot.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.suppot];
    [_suppot release];
    
    UILabel *collect = [[UILabel alloc] initWithFrame:CGRectMake(self.collectView.frame.origin.x + self.collectView.frame.size.width / 2 - 50 * SCREEN_WIDTH / 375, self.suppot.frame.origin.y, self.suppot.frame.size.width, self.suppot.frame.size.height)];
    collect.textAlignment = NSTextAlignmentCenter;
    collect.text = @"收藏本条";
    collect.textColor = [UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1];
    collect.font = [UIFont systemFontOfSize:15];
    [self addSubview:collect];
    [collect release];
    
    UIButton *Upbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    Upbutton.frame = CGRectMake(self.suppot.frame.origin.x, self.suppot.frame.origin.y + self.suppot.frame.size.height + 10, self.suppot.frame.size.width, 30 * SCREEN_HEIGHT / 667);
    [Upbutton setTitle:@"上一篇" forState:UIControlStateNormal];
    Upbutton.layer.cornerRadius = 5;
    Upbutton.layer.borderWidth = 1;
    Upbutton.clipsToBounds = YES;
    Upbutton.layer.borderColor = [UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1].CGColor;
    [Upbutton setTitleColor:[UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1] forState:UIControlStateNormal];
    [self addSubview:Upbutton];
    [Upbutton addTarget:self action:@selector(upAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.DownButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.DownButton.frame = CGRectMake(collect.frame.origin.x, collect.frame.origin.y + collect.frame.size.height + 10, collect.frame.size.width, 30 * SCREEN_HEIGHT / 667);
    [self.DownButton setTitle:@"下一篇" forState:UIControlStateNormal];
    self.DownButton.layer.cornerRadius = 5;
    self.DownButton.layer.borderWidth = 1;
    self.DownButton.clipsToBounds = YES;
    self.DownButton.layer.borderColor = [UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1].CGColor;
    [self.DownButton setTitleColor:[UIColor colorWithRed:0.4 green:0.66 blue:1 alpha:1] forState:UIControlStateNormal];
    [self addSubview:self.DownButton];
    [self.DownButton addTarget:self action:@selector(downAction) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)createGaryView
{
    self.garyView = [[UIView alloc] initWithFrame:CGRectMake(0, self.DownButton.frame.origin.y + self.DownButton.frame.size.height + 10, SCREEN_WIDTH, 20)];
    self.garyView.backgroundColor = [UIColor grayColor];
    self.garyView.alpha = 0.1;
    [self addSubview:self.garyView];
    [_garyView release];
}


/**
 *
 * 赞 按钮点击方法
 *  @param button self.supportButton
 */
- (void)supportAction:(UIButton *)button
{
    self.supportCount++;
    if (self.supportCount % 2 != 0) {
        button.selected = YES;
    } else if (self.supportCount % 2 == 0){
        button.selected = NO;
    }
}
/**
 *  收藏 按钮点击方法
 *
 *  @param button self.collectButton
 */
- (void)collectAction:(UIButton *)button
{
    self.collectCount++;
    if (self.collectCount % 2 != 0) {
        button.selected = YES;
    } else if (self.collectCount % 2 == 0){
        button.selected = NO;
    }
}

/**
 *  上一篇 按钮点击方法
 *
 *  @return UpButton
 */
- (void)upAction
{
    NSLog(@"up");
}

/**
 *  下一篇 按钮点击方法
 *
 *  @return DownButton
 */
- (void)downAction
{
    NSLog(@"down");
}






/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
